package cn.com.wangkai.wangkaisiji.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import cn.com.wangkai.wangkaisiji.R;

/**
 * Created by Administrator on 2016/11/16.
 */
public class Utils {

    public static void toast(Context context,String message){
        Toast toast=Toast.makeText(context,message,Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.show();
    }


    public static void ShowDialog(Activity context, String orderId,
                                  String money, final Callback callback) {
        final Dialog dialog = new Dialog(context, R.style.Dialog);
        View view = View.inflate(context, R.layout.view_dialog, null);
        dialog.setContentView(view);
        TextView tvcancel = (TextView) view.findViewById(R.id.tvcancel);
        TextView tvconfirm = (TextView) view.findViewById(R.id.tvconfirm);
        TextView tvOrderId = (TextView) view.findViewById(R.id.tv_orderId);
        TextView tvMoney = (TextView) view.findViewById(R.id.tv_money);
        final TextView etMessage = (EditText) view.findViewById(R.id.et_message);

        tvOrderId.setText("订单号  " + orderId);
        tvMoney.setText("￥" + money);
        WindowManager windowManager = context.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = (int) (display.getWidth() * 0.64); //设置宽度
        lp.height = (int) (display.getHeight() * 0.23); //设置高度
        dialog.getWindow().setAttributes(lp);


        tvcancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.onCancel(dialog);
            }
        });

        tvconfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.onConfirm(dialog, etMessage.getText().toString());
            }
        });
        dialog.show();
    }
    public interface Callback {

        void onConfirm(Dialog dialog, String message);

        void onCancel(Dialog dialog);

    }

}